package com.qianfeng.controller;

import com.qianfeng.dto.Page;
import com.qianfeng.dto.Result;
import com.qianfeng.entity.Attendance;
import com.qianfeng.entity.Subject;
import com.qianfeng.service.AttendanceService;
import com.qianfeng.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@ResponseBody
@CrossOrigin
@RequestMapping(value = "/subject")
@Controller
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    @RequestMapping(value = "/addSubject")
    public Result addSubject(@RequestBody Subject subject){
        subjectService.addSubject(subject);
        Result result = new Result();
        return result;
    }

    /**
     * 删除角色
     * @param subjectId
     * @return
     */
    @RequestMapping(value = "/deleteSubject")
    public Result deleteSubject(Integer subjectId){
        subjectService.deleteSubject(subjectId);
        Result result = new Result();
        return result;
    }

    /**
     * 更新角色
     * @param subject
     * @return
     */
    @RequestMapping(value = "/updateSubject")
    public Result updateSubject(@RequestBody Subject subject){
        subjectService.updateSubject(subject);
        Result result = new Result();
        return result;
    }

    @RequestMapping(value = "/getSubjectPage")
    public Result getSubjectPage(Integer pageNo,Integer pageSize){
        if(pageNo==null){
            pageNo=1;
        }
        if(pageSize==null){
            pageSize=5;
        }
        Page page = subjectService.getSubjectPage(pageNo,pageSize);
        Result result = new Result();
        result.setData(page);
        return result;

    }

    @RequestMapping(value = "/getSubjectList")
    public Result getSubjectList(){
        List<Subject> subjectList = subjectService.getSubjectList();
        Result result = new Result();
        result.setData(subjectList);
        return result;
    }


    @RequestMapping(value = "/getListBySubjectId")
    public Result getListBySubjectId(Integer subjectId){
        List<Subject> listBySubjectId = subjectService.getListBySubjectId(subjectId);
        Result result = new Result();
        result.setData(listBySubjectId);
        return result;
    }
}
